"use strict";

const Controller = require("egg").Controller;

class HomeController extends Controller {
    /**
     * 应用首页
     */
    async index() {
        // 解构 this 获取 ctx 对象
        const { ctx } = this;
        // 响应请求
        ctx.body = "Hi, egg ~";
    }

    /**
     * 注册
     */
    async register() {
        // 解构 this 获取 ctx 对象
        const { ctx } = this;
        // 解构参数
        const { username, password, nickname } = ctx.request.body;
        // 必填字段，非空校验
        if (!username || !password || !nickname) {
            ctx.body = {
                code: 400,
                message: "缺少必须参数",
            };
            return;
        }
        // 用户名不能重复
        const user = await this.service.user.findByUsername(username);
        console.log("user", user);
        ctx.body = res;
    }
}

module.exports = HomeController;
